package com.math3d;

import java.util.Arrays;

/**
 * Created by JhonKkk on 2018/11/3.
 */

public class Vector2fv {
    float vec[] = new float[2];

    public Vector2fv(float[] vec) {
        this.vec = vec;
    }
    public Vector2fv(float x, float y){
        vec[0] = x;
        vec[1] = y;
    }

    public Vector2fv(Vector2fv vector2fv) {
        vec[0] = vector2fv.vec[0];
        vec[1] = vector2fv.vec[1];
    }

    public float[] getVec() {
        return vec;
    }

    public void setVec(float[] vec) {
        this.vec = vec;
    }
    public final void normalize(){
        double length = vec[0] * vec[0] + vec[1] * vec[1];
        if(length > 0){
            //归一化
            length = Math.sqrt(length);
            vec[0] *= length;
            vec[1] *= length;
        }
    }
    public final void applyTo(double f){
        vec[0] *= f;
        vec[1] *= f;
    }
    public final Vector2fv apply(float f){
        Vector2fv copy = new Vector2fv(this);
        copy.vec[0] *= f;
        copy.vec[1] *= f;
        return copy;
    }
    public final double dot(float x, float z){
        return 0;
    }
    public final double dot(Vector2fv tar){
        return vec[0] * tar.vec[0] + vec[1] * tar.vec[1];
    }
    @Override
    public String toString() {
        return "Vector2fv{" +
                "vec=" + Arrays.toString(vec) +
                '}';
    }
}
